//
//  AddFavViewController.m
//  floodAdvisor
//
//  Created by Long Ho on 2/22/10.
//  Copyright 2010 Lafayette College. All rights reserved.
//

#import "AddFavViewController.h"
#import "CustomTableViewCellTextField.h"
#import "CustomTableViewCellButton.h"

@implementation AddFavViewController

NSMutableArray *items;

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/


- (void)viewDidLoad {
    [super viewDidLoad];
	
	//self.tableView.editing = YES;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
	 self.navigationItem.rightBarButtonItem = self.editButtonItem;
	
	items = [[NSMutableArray alloc] initWithCapacity: 3];
	
	NSArray *name = [NSArray arrayWithObjects: @"", nil];
	
	
	NSArray *addr = [NSArray arrayWithObjects: @"111 Quad Drive", @"Easton", @"PA", @"18042", nil];
	
	
	NSArray *saveButton = [NSArray arrayWithObjects: @"Save Favorite", nil];
	
	
	[items addObject: name];
	[items addObject: addr];
	[items addObject: saveButton];
	
	NSLog(@"Huh %d", [items count]);
	
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	NSLog(@"hhau %d", [items count]);
    return [items count];
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[items objectAtIndex:section] count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	
	int currentSection = indexPath.section;
	NSString *cellValue = @"";
	
	
    if (cell == nil) {
		
		switch (currentSection) {
			case 0:
				cell = [[[CustomTableViewCellTextField alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
				cellValue = [[items objectAtIndex: currentSection] objectAtIndex:indexPath.row];
				[((CustomTableViewCellTextField *)cell).textField setText: cellValue];
				break;
			case 1:
				cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
				cellValue = [[items objectAtIndex: currentSection] objectAtIndex:indexPath.row];
				[cell.textLabel setText: cellValue];
				break;
			case 2:
				cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
				[cell.textLabel setText:@"Save"];
				cell.textLabel.textAlignment = UITextAlignmentCenter;
				break;

			default:
				cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
				[cell.textLabel setText:@""];
				break;
		}
		
		

        
    }
    
	
	

	
	
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController];
	// [anotherViewController release];
	
	UITableViewCell *cell = [self tableView: tableView cellForRowAtIndexPath:indexPath];
	
	NSLog(@"%@",cell.textLabel.text);
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

- (NSString *) tableView: (UITableView *) tableView titleForHeaderInSection: (NSInteger) section{
	switch (section) {
		case 0:
			return @"Favorite Name";
		case 1:
			return @"Address";
		case 2:
			return @"";
		default:
			return @"";
	}
	
}






- (void)dealloc {
	[items release];
    [super dealloc];
}


@end

